<template>
  <div>
    <n-card :bordered="false" class="mt-4 proCard">
      <n-grid cols="2" responsive="screen">
        <n-grid-item offset="0 s:0 m:1 l:1 xl:1 2xl:1">
          <n-form
            :label-width="90"
            :model="formValue"
            :rules="rules"
            label-placement="top"
            ref="formRef"
            class="py-8"
          >
            <n-form-item label="名称" path="title">
              <n-input v-model:value="formValue.title" placeholder="输入名称" />
            </n-form-item>
            <div style="margin-left: 80px">
              <n-space>
                <n-button>返回</n-button>
              </n-space>
            </div>
          </n-form>
        </n-grid-item>
      </n-grid>
    </n-card>
  </div>
</template>

<script lang="ts" setup>
  import { ref, reactive, onMounted } from 'vue';
  import { useMessage } from 'naive-ui';
  import '@vueup/vue-quill/dist/vue-quill.snow.css';
  import { ResultEnum } from '@/enums/httpEnum';
  import { useRouter } from 'vue-router';
  import { getUser } from '@/api/user/user';

  const id: any = ref(useRouter().currentRoute.value.params.id);
  const rules = {
    title: {
      required: true,
      message: '请输入课程名称',
      trigger: 'blur',
    },
  };

  const formRef: any = ref(null);
  const message = useMessage();

  const defaultValueRef = () => ({
    id: 0,
    title: '',
    cover: '',
    price: 0,
    sex: 1,
    shop_type: 2,
    status: 1,
    brief: '',
    content: '',
  });

  let formValue = reactive(defaultValueRef());

  const getData = async () => {
    const response: any = await getUser(formValue.id);
    if (response.code === ResultEnum.SUCCESS) {
      Object.assign(formValue, response.data);
    }
  };

  onMounted(() => {
    formValue.id = id.value;
    if (formValue.id != 0) {
      getData();
    }
  });
</script>

<style lang="less">
  .ql-toolbar.ql-snow {
    border-top: none;
    border-left: none;
    border-right: none;
    border-bottom: 1px solid #eee;
    margin-top: -10px;
  }

  .ql-container.ql-snow {
    border: none;
  }
</style>
